<template>
  <div class="search-bar">
    <el-form :inline="true" :model="formItem" class="form-filter" size="mini">
      <el-form-item>
        <el-radio-group v-model="formItem.s_status" @change="search">
          <el-radio-button key="all" label="">全部</el-radio-button>
          <el-radio-button key="finished" label="finished">已完成</el-radio-button>
          <el-radio-button key="inspecting" label="inspecting">进行中</el-radio-button>
          <el-radio-button key="notStarted" label="notStarted">待处理</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-select v-model="formItem.s_institutionCode" clearable placeholder="请选择厅局" size="mini" @change="search">
          <el-option v-for="(item) in types" :key="item.code" :label="item.name " :value="item.code" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-date-picker
          v-model="timeRangeCreateTimeStart"
          clearable
          type="datetimerange"
          :picker-options="pickerOptions"
          range-separator="至"
          start-placeholder="查询起始时间"
          end-placeholder="查询终止时间"
          align="right"
          value-format="timestamp"
          size="mini"
          @change="search"
        />
      </el-form-item>
      <el-form-item>
        <el-button plain icon="el-icon-search" @click="search" />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
// import { list } from '@neu/dcom-ui/api/institutions'
// 定义一个查询表单原始项
const formItem = {
  s_status: '',
  s_institutionCode: '',
  s_startTaskTimeBegin: '',
  s_startTaskTimeEnd: ''
}

export default {
  name: 'HnInspectionFilter',
  data() {
    return {
      formItem: {
        ...formItem
      },
      /** 机构 */
      types: [],
      /** 存储时间范围 */
      timeRangeCreateTimeStart: [],
      /** 时间选择器 */
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }]
      }

    }
  },
  computed: {
    status: function() {
      return this.$attrs['temp-query'] ? this.$attrs['temp-query'].s_status : 'all'
    }
  },
  watch: {
    status: function(v1, v2) {
      this.formItem.s_status = v1
    }
  },
  created() {
    this.types = this.$store.getters['dcom/projectUserInfo'].institutions
  },
  methods: {
    // 查询按钮点击事件处理
    search: function() {
      if (this.timeRangeCreateTimeStart && this.timeRangeCreateTimeStart.length !== 0) {
        this.formItem.s_startTaskTimeBegin = this.timeRangeCreateTimeStart[0]
        this.formItem.s_startTaskTimeEnd = this.timeRangeCreateTimeStart[1]
      } else {
        this.formItem.s_startTaskTimeBegin = ''
        this.formItem.s_startTaskTimeEnd = ''
      }
      this.$parent.filter(this.formItem)
    },
    // 重置按钮点击事件处理
    reset: function() {
      this.formItem = {
        ...formItem
      }
      this.search()
    },
    onChange: function(val) {
      this.$parent.onResize()
    },
    onGlobeSearchInputChange(value) {
      if (value === '') {
        this.search()
      }
    }
  }
}
</script>
